<?php


require_once FRAMEWORK_DIR."/libraries/neocasta/registry.php";

class RegistryTestCaseOutput extends UnitTestCase {

	function setUp() {

        $registry = &NRegistry::getInstance();
        $registry->save();
    }
    function tearDown() {
        $registry = &NRegistry::getInstance();
        $registry->restore();
    }

	function testAccess() {
        $registry = &new NRegistry();
        $this->assertFalse($registry->isEntry('a'));
        $this->assertNull($registry->getEntry('a'));
        $thing = 'thing';
        $registry->setEntry('a', $thing);
        $this->assertTrue($registry->isEntry('a'));
        $this->assertReference($registry->getEntry('a'), $thing);
    }
    function testSingleton() {
        $this->assertReference(
                NRegistry::getInstance(),
                NRegistry::getInstance());
        $this->assertIsA(NRegistry::getInstance(), 'NRegistry');
    }

function testSaveAndRestore() {
        $registry = &new NRegistry();
        $a = 'a';
       $ret =  &$registry->setEntry('a', $a);
	 $this->assertReference($registry->getEntry('a'), $ret);
 	//$this->assertReference($as, $ret);
         $registry->save();

	
	// $this->assertReference($registry->getEntry('a'), $b);

        $this->assertFalse($registry->isEntry('a'));
        $b = 'b';
        $registry->setEntry('a', $b);
        $this->assertReference($registry->getEntry('a'), $b);
        $registry->restore();
        $this->assertReference($registry->getEntry('a'), $a);
    }

function testPushToEntry(){
	$aArr = array();
	for ($i=1;$i<10;$i++){
	$_oObj = new stdClass;
	$_oObj->id=$i;
	$_oObj->name='name'.$i;
	$aArr[]=$_oObj;	
	unset($_oObj);
	}
	
	$registry = NRegistry::getInstance();
	$registry->pushToEntry($aArr,'prepitems','id');
	$prepitems = $registry->getEntry('prepitems');
	$this->assertEqual($prepitems[2]->name,'name2');
	$this->assertEqual($prepitems[1]->name,'name1');

	unset($prepitems);
	unset($aArr);

	$aArr = array();
	for ($i=10;$i<20;$i++){
	$_oObj = new stdClass;
	$_oObj->id=$i;
	$_oObj->name='name'.$i;
	$aArr[]=$_oObj;	
	unset($_oObj);
	}
	$this->assertEqual($aArr[0]->name,'name10');
	$this->assertEqual($aArr[2]->name,'name12');

	$registry = NRegistry::getInstance();
	$registry->pushToEntry($aArr,'prepitems','id');
	$prepitems = &$registry->getEntry('prepitems');
	$this->assertEqual($prepitems[1]->name,'name1');
	$this->assertEqual($prepitems[12]->name,'name12');


	
}


}


?>